using Microsoft.AspNetCore.Mvc;
using MESData.ErrorCode;
using BOMAPI.DTO;
using BOMAPI.Services;

namespace BOMAPI.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ManagementController : ControllerBase
    {
        private readonly IManagementService _managementService;

        public ManagementController(IManagementService managementService)
        {
            _managementService = managementService;
        }

        /// <summary>
        /// ManagementModel 分页查询
        /// </summary>
        [HttpPost("query")]
        public async Task<ApiPageing<ManagementResultDto>> Query([FromBody] ManagementQueryDto dto)
        {
            return await _managementService.GetManagementAsync(dto);
        }

        /// <summary>
        /// 兼容 GET 查询（可通过 query string 传参）
        /// </summary>
        [HttpGet("query")]
        public async Task<ApiPageing<ManagementResultDto>> QueryGet([FromQuery] ManagementQueryDto dto)
        {
            return await _managementService.GetManagementAsync(dto);
        }

        /// <summary>
        /// 创建新的ManagementModel
        /// </summary>
        [HttpPost("create")]
        public async Task<ApiResult<ManagementResultDto>> Create([FromBody] ManagementCreateDto createDto)
        {
            return await _managementService.CreateManagementAsync(createDto);
        }
    }
}


